/* 
 * Copyright 2014 ShangDao.Ltd  All rights reserved.
 * SiChuan ShangDao.Ltd PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * 
 * @HomeCenterAdapter.java  2014-9-10 上午10:20:05 - Carson
 * @author Guzhu
 * @email:muyi126@163.com
 * @version 1.0
 */

package com.android.tiango.baba.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.scsd.tiango.R;
import com.android.tiango.baba.act.ActBaList;
import com.android.tiango.baba.entity.BarModel;
import com.android.tiango.baba.util.Constants;
import com.android.tiango.baba.util.ImageLoader;

public class HomeCenterAdapter extends BaseAdapter {
	private Context context;
	private ArrayList<BarModel> list;
	private ImageLoader mLoader;

	public HomeCenterAdapter(Context context, ArrayList<BarModel> list) {
		this.context = context;
		this.list = list;
		mLoader = new ImageLoader(context, R.drawable.ic_default);
	}

	@Override
	public int getCount() {

		return list.size();
	}

	@Override
	public BarModel getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (null == convertView) {
			convertView = LayoutInflater.from(context).inflate(R.layout.item_home_center, null);
			holder = new ViewHolder();
			holder.ll_bg = (LinearLayout) convertView.findViewById(R.id.ll_bg);
			holder.tv_title = (TextView) convertView.findViewById(R.id.tv_title);
			holder.tv_content = (TextView) convertView.findViewById(R.id.tv_content);
			holder.iv_bg = (ImageView) convertView.findViewById(R.id.iv_bg);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		final BarModel bean = list.get(position);
		if (null != bean) {
			mLoader.loadImage(bean.getBarIcon(), holder.iv_bg);
			holder.tv_title.setText(bean.getBarName());
			holder.tv_content.setText(bean.getBarSummary());
		}
//		convertView.setOnClickListener(new OnClickListener() {
//
//			@Override
//			public void onClick(View v) {
//				Intent intent = new Intent(context, ActBaList.class);
//				intent.putExtra(Constants.BARID, bean);
//				context.startActivity(intent);
//			}
//		});
		return convertView;
	}

	class ViewHolder {
		private LinearLayout ll_bg;
		private TextView tv_title;
		private TextView tv_content;
		private ImageView iv_bg;
	}
}
